package com.mezo.athena.web.controller.system;

import com.mezo.athena.common.annotation.Log;
import com.mezo.athena.common.core.controller.BaseController;
import com.mezo.athena.common.core.domain.AjaxResult;
import com.mezo.athena.common.core.page.TableDataInfo;
import com.mezo.athena.common.enums.BusinessType;
import com.mezo.athena.common.utils.poi.ExcelUtil;
import com.mezo.athena.system.domain.RyDevice;
import com.mezo.athena.system.service.IRyDeviceService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备Controller
 * 
 * @author athena
 * @date 2024-11-13
 */
@RestController
@RequestMapping("/system/device")
public class RyDeviceController extends BaseController
{
    @Autowired
    private IRyDeviceService ryDeviceService;

    /**
     * 查询设备列表
     */
    @PreAuthorize("@ss.hasPermi('system:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(RyDevice ryDevice)
    {
        startPage();
        List<RyDevice> list = ryDeviceService.selectRyDeviceList(ryDevice);
        return getDataTable(list);
    }

    /**
     * 导出设备列表
     */
    @PreAuthorize("@ss.hasPermi('system:device:export')")
    @Log(title = "设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RyDevice ryDevice)
    {
        List<RyDevice> list = ryDeviceService.selectRyDeviceList(ryDevice);
        ExcelUtil<RyDevice> util = new ExcelUtil<RyDevice>(RyDevice.class);
        util.exportExcel(response, list, "设备数据");
    }

    /**
     * 获取设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:device:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ryDeviceService.selectRyDeviceById(id));
    }

    /**
     * 新增设备
     */
    @PreAuthorize("@ss.hasPermi('system:device:add')")
    @Log(title = "设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RyDevice ryDevice)
    {
        return toAjax(ryDeviceService.insertRyDevice(ryDevice));
    }

    /**
     * 修改设备
     */
    @PreAuthorize("@ss.hasPermi('system:device:edit')")
    @Log(title = "设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RyDevice ryDevice)
    {
        return toAjax(ryDeviceService.updateRyDevice(ryDevice));
    }

    /**
     * 删除设备
     */
    @PreAuthorize("@ss.hasPermi('system:device:remove')")
    @Log(title = "设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ryDeviceService.deleteRyDeviceByIds(ids));
    }
}
